import window from './window';

do { window::mount Root };

// TODO: mouse enter => Some pos, mouse out => None
const MousePosition: ui::Hook[Source[(NormalFloat,NormalFloat)]] :=
    &(k) =>
        \ pos := sync { Bus::[(NormalFloat,NormalFloat)] () },
        \ id := sync { gen-monotonic-id-string () },
        let cpt := { k { watch pos } },
        (cpt with { ui::Event ({ "mousemove.hook?" id },
            \ x := ui::extract-float 'webuiCurrentTargetX',
            \ y := ui::extract-float 'webuiCurrentTargetY',
            { ui::trigger (pos <- (x, y)) }
        )});

const Root: ui::Component :=
    let container := { ui::StyledContainer ['container'] },
    let box := { ui::StyledContainer ['box'] },
    { container [
        \ pos := use MousePosition,
        { box [
            pos
                . { map &(x,y) => { "x=?, y=?" (x.{String}, y.{String}) } }
                . { Computed { beginning: [''] } }
                . { ui::Label }
        ] }
    ] };
